package com.imti.receiverdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver
{

    private static final String TAG = MyReceiver.class.getSimpleName();
    /**
     * 接收广播后的回调方法，用于处理接收到的广播
     *
     * @param context Context
     * @param intent 广播的消息对象
     */
    @Override
    public void onReceive(Context context, Intent intent)
    {
        String action = intent.getAction();

        switch (action)
        {
            //接收指定的系统广播（开机启动完成）
            case Intent.ACTION_BOOT_COMPLETED:

                Toast.makeText(context, "开机启动完成！",
                    Toast.LENGTH_LONG).show();
                break;

            case "com.imti.broadcast.NORMAL":
                Log.d(TAG, "接收到自定义广播");
                String text = intent.getStringExtra("extra_text");
                Log.d(TAG, "全局广播接收器接收到：" + text);
                break;
        }
    }
}